package com.zc.web.controller.timedown;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zc.common.utils.poi.ExcelUtil;
import com.zc.web.service.ITodayGoalService;

import com.zc.web.domain.TodayGoal;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zc.common.annotation.Log;
import com.zc.common.core.controller.BaseController;
import com.zc.common.core.domain.AjaxResult;
import com.zc.common.enums.BusinessType;
import com.zc.common.core.page.TableDataInfo;

/**
 * 今日目标Controller
 * 
 * @author zc
 * @date 2025-09-29
 */
@RestController
@RequestMapping("/wx/goal")
public class TodayGoalController extends BaseController
{
    @Autowired
    private ITodayGoalService todayGoalService;

    /**
     * 查询今日目标列表
     */
    @PreAuthorize("@ss.hasPermi('wx:goal:list')")
    @GetMapping("/list")
    public TableDataInfo list(TodayGoal todayGoal)
    {
        startPage();
        List<TodayGoal> list = todayGoalService.selectTodayGoalList(todayGoal);
        return getDataTable(list);
    }

    /**
     * 导出今日目标列表
     */
    @PreAuthorize("@ss.hasPermi('wx:goal:export')")
    @Log(title = "今日目标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TodayGoal todayGoal)
    {
        List<TodayGoal> list = todayGoalService.selectTodayGoalList(todayGoal);
        ExcelUtil<TodayGoal> util = new ExcelUtil<TodayGoal>(TodayGoal.class);
        util.exportExcel(response, list, "今日目标数据");
    }

    /**
     * 获取今日目标详细信息
     */
    @PreAuthorize("@ss.hasPermi('wx:goal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(todayGoalService.selectTodayGoalById(id));
    }

    /**
     * 新增今日目标
     */
    @PreAuthorize("@ss.hasPermi('wx:goal:add')")
    @Log(title = "今日目标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TodayGoal todayGoal)
    {
        return toAjax(todayGoalService.insertTodayGoal(todayGoal));
    }

    /**
     * 修改今日目标
     */
    @PreAuthorize("@ss.hasPermi('wx:goal:edit')")
    @Log(title = "今日目标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TodayGoal todayGoal)
    {
        return toAjax(todayGoalService.updateTodayGoal(todayGoal));
    }

    /**
     * 删除今日目标
     */
    @PreAuthorize("@ss.hasPermi('wx:goal:remove')")
    @Log(title = "今日目标", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(todayGoalService.deleteTodayGoalByIds(ids));
    }
}
